//
//  AppDelegate.m
//  B段项目
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 谢美娜. All rights reserved.
//

#import "AppDelegate.h"
#import "SHD_MainViewController.h"
#import "XMN_LeftViewController.h"
#import "Header.h"
#import "WelcomeView.h"

@interface AppDelegate ()

@property(nonatomic, retain)UIImageView *launchImageView;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[FontSizeManage ChangeSize] setFontSize:1];
    //电量条颜色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    
    //判断是否为夜间模式
    [ThemeManage shareThemeManage].isNight = [[NSUserDefaults standardUserDefaults] boolForKey:@"night"];
    
    _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [_window makeKeyAndVisible];
    [_window NightWithType:UIViewColorTypeNormal];
    
    SHD_MainViewController *mainVC = [[SHD_MainViewController alloc]init];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:mainVC];
    _menu = [[DDMenuController alloc]initWithRootViewController:nav];
    XMN_LeftViewController *leftVC = [[XMN_LeftViewController alloc]init];
    _menu.leftViewController = leftVC;
    _window.rootViewController = _menu;
    
    //设置引导页
    //判断App是否是首次运行
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"first"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"first"];
        WelcomeView *welcomeView = [[WelcomeView alloc]initWithFrame:_window.frame];
        [_window addSubview:welcomeView];
    }else{
        //启动页
        self.launchImageView = [[UIImageView alloc] initWithFrame:_window.frame];
        _launchImageView.image = [UIImage imageNamed:@"启动页1"];
        [_window addSubview:_launchImageView];
        
        //放大动画
        CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        basicAnimation.fromValue = [NSNumber numberWithDouble:1];//原始比例
        basicAnimation.toValue = [NSNumber numberWithDouble:1.3];//放大倍数
        [basicAnimation setDuration:3];
        [_launchImageView.layer addAnimation:basicAnimation forKey:@"launch"];
        
        //移除启动页
        [UIView animateWithDuration:3 animations:^{
            _launchImageView.alpha = 0;
        }];
        [UIView animateWithDuration:3 animations:^{
            _launchImageView.alpha = 0;
        } completion:^(BOOL finished) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [_launchImageView removeFromSuperview];
            });
        }];
    }
    
    
    // Override point for customization after application launch.
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
